package com.study.a07Test;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Sever {
    public static void main(String[] args) throws IOException {

        ServerSocket ss=new ServerSocket(9000);

        System.out.println("等待连接...");
        Socket socket=ss.accept();
        System.out.println("连接成功...");

        InputStreamReader ISR=new InputStreamReader(socket.getInputStream());

        //需要结束标记，不然会一直等待
        int b;
        while((b=ISR.read())!=-1){
            System.out.print((char)b);
        }

        //回写数据
        String str="有多开心？";
        OutputStream os=socket.getOutputStream();
        os.write(str.getBytes());

        socket.close();
        ss.close();


    }
}
